<template>
  <div>
    <div class="form_wrap">
      <div>
        <el-input></el-input>
        <el-button type="success">查询</el-button>
      </div>
      <el-button type="primary" @click="open">添加</el-button>
    </div>
    <el-dialog title="添加视频" width="40%" :visible.sync="videoFlag">
      <el-form label-position="left" label-width="80px">
        <el-form-item label="视频上传">
          <el-input v-model="videoUrl" disabled></el-input>
          <el-upload
            class="upload-demo"
            :auto-upload="true"
            :on-success="handleAvatarSuccess"
            ref="upload"
            :on-change="getFile"
            action="http://localhost:3000/VueHandler/UpLoadVideoHandler"
          >
            <el-button size="small" type="primary">选择视频</el-button>
            <div slot="tip" class="el-upload__tip">
              只能上传mp4,avi文件，且不超过1GB
            </div>
          </el-upload>
        </el-form-item>
        <el-form-item label="视频名称">
          <el-input v-model="Vname"></el-input>
        </el-form-item>
        <el-form-item label="视频时长">
          <el-input v-model="Vtime"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer">
        <el-button type="success" @click="sure">确定</el-button>
        <el-button type="danger" @click="videoFlag = false">取消</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { _addVideo } from '../../api/video'
export default {
  data () {
    return {
      videoFlag: false,
      videoUrl: '',
      Vname: '',
      Vtime: ''
    }
  },
  methods: {
    open () {
      this.videoFlag = true
    },
    async sure () {
      // 添加视频

      var res = await _addVideo({
        Vurl: this.videoUrl,
        Vname: this.Vname,
        Vtime: this.Vtime
      })
      if (res.data.success) {
        this.$message.success('添加视频成功')
      }
      this.Vname = ''
      this.Vtime = ''
      this.videoUrl = ''
      this.videoFlag = false
      console.log(res)
    },
    getFile (event) {
      console.log(event)
      console.log(event.fileName)
      console.log(event.fileName)
    },
    handleAvatarSuccess (res) {
      //视频上传成功
      console.log('成功')
      console.log(res)
      if (res.err) {
        this.$message.error('上传失败')
      }
      this.videoUrl = res.cacheName
    }
  }
}
</script>
<style lang="less" scoped>
.form_wrap {
  display: flex;
  justify-content: space-between;
  margin: 30px 0;
  > div {
    display: flex;
  }
}
</style>
